package com.ken.blog.tools;

import java.util.HashMap;
import java.util.Map;

/**
 * 分页工具
 */
public class Pagination {
    /**
     * 简单分页工具
     *
     * @param totalPage
     * @param currentPage
     * @return
     */
    public static Map simgle(int totalPage, int currentPage) {
        Map map = new HashMap();

        int nextPage = 0;
        int prePage = -1;
        if (totalPage <= 1) {
            //只有一页的时候，没有上一页下一页
        } else if (currentPage >= totalPage) {
            prePage = currentPage - 2;
        } else if (currentPage > 1 && currentPage < totalPage) {
            prePage = currentPage - 2;
            nextPage = currentPage;
        } else if (currentPage == 1) {
            prePage = -1;
            nextPage = currentPage;
        }

        map.put("prePage", prePage);
        map.put("nextPage", nextPage);

        return map;
    }

    /**
     * 处理url分页参数，获取当前分页数码
     *
     * @param page
     * @return
     */
    public static int getPageSize(String page) {
        int pageSize = 0;
        if (page != null) {
            pageSize = Integer.valueOf(page).intValue();
        }
        return pageSize;
    }
}
